#include	"capinc.h"

int	SetHeader(int nThr, _BGF_MSG *pstMsg, int nBodyLength, int nMsgType, int nServiceCode, _MSG_HEAD_BGF *pstReqHead)
{
	_MSG_HEAD_BGF	*pstHead = &pstMsg->stHead;
    int 	nReqServiceCode;
	char	szOut[128];

	memset(pstHead, 0x00, BGF_HEAD_SIZE);

    SetValueN0(pstHead->version, 1, sizeof(pstHead->version));
    SetValueN0(pstHead->messageType, nMsgType, sizeof(pstHead->messageType));
#if	0
    SetValueN0(pstHead->serviceCode, nServiceCode, sizeof(pstHead->serviceCode));
#else
	GetValue(pstReqHead->serviceCode, szOut, sizeof(pstReqHead->serviceCode)); 
	nReqServiceCode = atoi(szOut);
    SetValueN0(pstHead->serviceCode, nReqServiceCode, sizeof(pstHead->serviceCode));
#endif
    SetValue(pstHead->cooperationCompanyCode, "123456", sizeof(pstHead->cooperationCompanyCode));
    SetValue(pstHead->ApprovalDateTime, "20130801120534", sizeof(pstHead->ApprovalDateTime));
    SetValue(pstHead->merchantBranchCode, "1234567890", sizeof(pstHead->merchantBranchCode));
    SetValue(pstHead->hangCode, "12345678", sizeof(pstHead->hangCode));
    SetValueN(pstHead->deviceType, 1, sizeof(pstHead->deviceType));
    SetValue(pstHead->deviceId, "1234567890", sizeof(pstHead->deviceId));
    SetValueN(pstHead->cardType, 1, sizeof(pstHead->cardType));
    SetValue(pstHead->cardId, "1234567890123456", sizeof(pstHead->cardId));
    SetValueN(pstHead->requestMethodCode, 1, sizeof(pstHead->requestMethodCode));
    SetValueN(pstHead->bodyLength, nBodyLength, sizeof(pstHead->bodyLength));

	GetValue(pstHead->bodyLength, szOut, sizeof(pstHead->bodyLength));
	Log(LOG_I, "[%4d] messageType(%d) serviceCode(%d) nBodyLength (%d)(%s)\n",
		nThr, nMsgType, nServiceCode, nBodyLength, szOut);

	return	BGF_HEAD_SIZE;
}

int SimRetrieveRsp_setValue(int nThr, char *pRsp, _BGF_MSG *pstBgfReq)
{
	_BGF_MSG			*pstBgfRsp = &DEV_SESS(nThr).stRsp;
	//_BGF_RETRIEVE_REQ	*pstReq = &pstBgfReq->stD.stReq.stRetrieve;
	_BGF_RETRIEVE_RSP	*pstRsp = &pstBgfRsp->stD.stRsp.stRetrieve;

    char        szResultCode[4+1];
    char        szGlobalSerialNo[20];
	int			nProductCount, i, nErrorMessageLength, nAmount;
	char		szErrorMessage[128];

	int			nEnco = 0;
	char		szOut[128];

	/////////////////////////////
	//	BODY
	/////////////////////////////
	//
	memset(pRsp, 0x20, BGF_BODY_SIZE);

	memset(szResultCode, 0x20, sizeof(szResultCode));
	memset(szGlobalSerialNo, 0x20, sizeof(szGlobalSerialNo));
	memset(szErrorMessage, 0x20, sizeof(szErrorMessage));

    strcpy(szResultCode, "0000");
	nAmount = 1000;
	strcpy(szErrorMessage, "RETRIEVE ERROR MESSAGE");
	nErrorMessageLength = strlen(szErrorMessage);
	
    Log(LOG_I, "[%4d] nEnco (%d) (%s)\n", nThr, nEnco, szResultCode);
	nEnco += SetValue(pRsp+nEnco, szResultCode, sizeof(pstRsp->resultCode)); 
	nEnco += SetValue(pRsp+nEnco, "20131013231639000123", sizeof(pstRsp->globalSerialNo)); 
	nEnco += SetValueN(pRsp+nEnco, nAmount, sizeof(pstRsp->amount)); 
	nEnco += SetValueN(pRsp+nEnco, 1, sizeof(pstRsp->productCount)); 

	nProductCount = 1;
    Log(LOG_I, "[%4d] productCount(%s)(%d)\n", nThr, szOut, nProductCount);

	for(i=0; i<nProductCount; i++)
	{
		nEnco += SetValue(pRsp+nEnco, "1000", sizeof(pstRsp->stPlu[i].productId)); 
		nEnco += SetValue(pRsp+nEnco, "1000", sizeof(pstRsp->stPlu[i].productBarcode)); 
		nEnco += SetValue(pRsp+nEnco, "1", sizeof(pstRsp->stPlu[i].productNumber)); 
		nEnco += SetValue(pRsp+nEnco, "10", sizeof(pstRsp->stPlu[i].productProviderCode)); 
		nEnco += SetValue(pRsp+nEnco, "1000", sizeof(pstRsp->stPlu[i].productCoPrice)); 
		nEnco += SetValue(pRsp+nEnco, "1000", sizeof(pstRsp->stPlu[i].productMaPrice)); 
	}
	nEnco += SetValueN(pRsp+nEnco, nErrorMessageLength, sizeof(pstRsp->errorMessageLength)); 
	nEnco += SetValue(pRsp+nEnco, szErrorMessage, nErrorMessageLength); 

    Log(LOG_I, "[%4d] Retrieve Rsp BodyLen(%d)\n", nThr, nEnco);

	return nEnco;
}

int SimApprovalRsp_setValue(int nThr, char *pRsp, _BGF_MSG *pstBgfReq)
{
	_BGF_MSG			*pstBgfRsp = &DEV_SESS(nThr).stRsp;
	_BGF_APPROVAL_RSP	*pstRsp = &pstBgfRsp->stD.stRsp.stApproval;

	char		szResultCode[4];
	int			nProductCount = 0, i;
	int			nAmount;
	char		szSaleCode[2];
	int			nSettlementAmount;
	char		szApprovalNo[20];
	int			nResponseFiller;
	char		szIsscompanyCode[2];
	char		szIsscompanyName[20];
	int			nErrorMessageLength;
	char		szErrorMessage[128];

	int			nEnco = 0;
	char		szOut[128];

	memset(pRsp, 0x00, BGF_BODY_SIZE);

	memset(szResultCode, 0x00, sizeof(szResultCode));
	memset(szSaleCode, 0x00, sizeof(szSaleCode));
	memset(szApprovalNo, 0x00, sizeof(szApprovalNo));
	memset(szIsscompanyCode, 0x00, sizeof(szIsscompanyCode));
	memset(szIsscompanyName, 0x00, sizeof(szIsscompanyName));
	memset(szErrorMessage, 0x00, sizeof(szErrorMessage));

	/////////////////////////////
	//	BODY
	/////////////////////////////
	//
    strcpy(szResultCode, "0000");
	nAmount = 1000;
	strcpy(szSaleCode, "01");
	nSettlementAmount = 200;
    strcpy(szApprovalNo, "1234567890");
	nResponseFiller = 100;
	strcpy(szIsscompanyCode, "01");
	strcpy(szIsscompanyName, "lotte2");
	strcpy(szErrorMessage, "SELL CANCEL ERROR MESSAGE");
	nErrorMessageLength = strlen(szErrorMessage);

	nEnco += SetValue(pRsp+nEnco, szResultCode, sizeof(pstRsp->resultCode)); 
	nEnco += SetValue(pRsp+nEnco, "20131013231639000123", sizeof(pstRsp->globalSerialNo)); 
	nEnco += SetValue(pRsp+nEnco, szApprovalNo, sizeof(pstRsp->approvalNo)); 
	nEnco += SetValueN(pRsp+nEnco, nSettlementAmount, sizeof(pstRsp->settlementAmount)); 
	nEnco += SetValueN(pRsp+nEnco, nAmount, sizeof(pstRsp->amount)); 
	nEnco += SetValue(pRsp+nEnco, szSaleCode, sizeof(pstRsp->saleCode)); 
	nEnco += SetValueN(pRsp+nEnco, 1, sizeof(pstRsp->productCount)); 

    Log(LOG_I, "[%4d] productCount(%s)(%d)\n", nThr, szOut, nProductCount);

	nProductCount = 1;
	for(i=0; i<nProductCount; i++)
	{
	/* Begin of PLU */
		nEnco += SetValue(pRsp+nEnco, "1000", sizeof(pstRsp->stPlu[i].productId)); 
		nEnco += SetValue(pRsp+nEnco, "1000", sizeof(pstRsp->stPlu[i].productBarcode)); 
		nEnco += SetValue(pRsp+nEnco, "1", sizeof(pstRsp->stPlu[i].productNumber)); 
		nEnco += SetValue(pRsp+nEnco, "10", sizeof(pstRsp->stPlu[i].productProviderCode)); 
		nEnco += SetValue(pRsp+nEnco, "1000", sizeof(pstRsp->stPlu[i].productCoPrice)); 
		nEnco += SetValue(pRsp+nEnco, "1000", sizeof(pstRsp->stPlu[i].productMaPrice)); 
	/* End of PLU */
	}

	nEnco += SetValueN(pRsp+nEnco, nResponseFiller, sizeof(pstRsp->responseFiller)); 
	nEnco += SetValue(pRsp+nEnco, szIsscompanyCode, sizeof(pstRsp->isscompanyCode)); 
	nEnco += SetValue(pRsp+nEnco, szIsscompanyName, sizeof(pstRsp->isscompanyName)); 

	nEnco += SetValueN(pRsp+nEnco, nErrorMessageLength, sizeof(pstRsp->errorMessageLength)); 
	nEnco += SetValue(pRsp+nEnco, szErrorMessage, nErrorMessageLength);

    Log(LOG_I, "[%4d] Approval Rsp BodyLen(%d)\n", nThr, nEnco);

	return nEnco;
}
int SimSellRsp_setValue(int nThr, char *pRsp, _BGF_MSG *pstBgfReq)
{
	_BGF_MSG	*pstBgfRsp = &DEV_SESS(nThr).stRsp;

	_BGF_SELLorCHARGE_RSP	*pstRsp = &pstBgfRsp->stD.stRsp.stSellCharge;

	char		szResultCode[4];
	char		szApprovalNo[20];
	int			nAmount;
	int			nResponseFiller;
	char		szIsscompanyCode[2];
	char		szIsscompanyName[20];
	char		szCrdAcqCompanyCode[2];
	char		szCrdAcqCompanyName[20];
	char		szCrdApprovalNo[8];
	int			nErrorMessageLength;
	char		szErrorMessage[128];

	int			nEnco = 0;
	
	memset(pRsp, 0x00, BGF_BODY_SIZE);

	memset(szResultCode, 0x00, sizeof(szResultCode));
	memset(szApprovalNo, 0x00, sizeof(szResultCode));
	memset(szIsscompanyCode, 0x00, sizeof(szResultCode));
	memset(szIsscompanyName, 0x00, sizeof(szResultCode));
	memset(szCrdAcqCompanyCode, 0x00, sizeof(szCrdAcqCompanyCode));
	memset(szCrdAcqCompanyName, 0x00, sizeof(szCrdAcqCompanyName));
	memset(szCrdApprovalNo, 0x00, sizeof(szCrdApprovalNo));
	memset(szErrorMessage, 0x00, sizeof(szErrorMessage));

	/////////////////////////////
	//	BODY
	/////////////////////////////
	
    strcpy(szResultCode, "0000");
    strcpy(szApprovalNo, "1234567890");
	nAmount = 1000;
	strcpy(szErrorMessage, "SELL ERROR MESSAGE");
	nErrorMessageLength = strlen(szErrorMessage);
	nResponseFiller = 100;
	strcpy(szIsscompanyCode, "01");
	strcpy(szIsscompanyName, "lotte2");
	strcpy(szCrdAcqCompanyCode, "01");
	strcpy(szCrdAcqCompanyName, "lotte");
	strcpy(szCrdApprovalNo, "12345678");

	nEnco += SetValue(pRsp+nEnco, szResultCode, sizeof(pstRsp->resultCode));
	nEnco += SetValue(pRsp+nEnco, "20131013231639000123", sizeof(pstRsp->globalSerialNo));
	nEnco += SetValue(pRsp+nEnco, szApprovalNo, sizeof(pstRsp->approvalNo));
	nEnco += SetValueN(pRsp+nEnco, nAmount, sizeof(pstRsp->amount)); 
	nEnco += SetValueN(pRsp+nEnco, nResponseFiller, sizeof(pstRsp->responseFiller)); 
	nEnco += SetValue(pRsp+nEnco, szIsscompanyCode, sizeof(pstRsp->isscompanyCode)); 
	nEnco += SetValue(pRsp+nEnco, szIsscompanyName, sizeof(pstRsp->isscompanyName));
	nEnco += SetValue(pRsp+nEnco, szCrdAcqCompanyCode, sizeof(pstRsp->crdAcqCompanyCode)); 
	nEnco += SetValue(pRsp+nEnco, szCrdAcqCompanyName, sizeof(pstRsp->crdAcqCompanyName)); 
	nEnco += SetValue(pRsp+nEnco, szCrdApprovalNo, sizeof(pstRsp->crdApprovalNo)); 

	nEnco += SetValueN(pRsp+nEnco, nErrorMessageLength, sizeof(pstRsp->errorMessageLength)); 
	nEnco += SetValue(pRsp+nEnco, szErrorMessage, nErrorMessageLength);

	return nEnco;
}

int SimSellCancelRsp_setValue(int nThr, char *pRsp, _BGF_MSG *pstBgfReq)
{
	_BGF_MSG	*pstBgfRsp = &DEV_SESS(nThr).stRsp;
	_BGF_SELLorCHARGE_CANCEL_RSP	*pstRsp = &pstBgfRsp->stD.stRsp.stSellChargeCancel;

	char		szResultCode[4];
	char		szApprovalNo[20];
	int			nAmount;
	char		szOriginalApprovalDate[14];
	int			nOriginalApprovalAmount;
	char		szOriginalApprovalNo[20];
	char		szSaleCode[2];
	int			nResponseFiller;
	char		szIsscompanyCode[2];
	char		szIsscompanyName[20];
	char		szCrdAcqCompanyCode[2];
	char		szCrdAcqCompanyName[20];
	char		szCrdApprovalNo[2];
	int			nErrorMessageLength;
	char		szErrorMessage[128];

	int			nEnco = 0;

	memset(pRsp, 0x00, BGF_BODY_SIZE);

	memset(szResultCode, 0x00, sizeof(szResultCode));
	memset(szSaleCode, 0x00, sizeof(szResultCode));
	memset(szApprovalNo, 0x00, sizeof(szResultCode));
	memset(szOriginalApprovalDate, 0x00, sizeof(szOriginalApprovalDate));
	memset(szOriginalApprovalNo, 0x00, sizeof(szOriginalApprovalNo));
	memset(szCrdAcqCompanyCode, 0x00, sizeof(szCrdAcqCompanyCode));
	memset(szCrdAcqCompanyName, 0x00, sizeof(szCrdAcqCompanyName));
	memset(szCrdApprovalNo, 0x00, sizeof(szCrdApprovalNo));
	memset(szIsscompanyCode, 0x00, sizeof(szIsscompanyCode));
	memset(szIsscompanyName, 0x00, sizeof(szIsscompanyName));
	memset(szErrorMessage, 0x00, sizeof(szErrorMessage));

	/////////////////////////////
	//	BODY
	/////////////////////////////
	
    strcpy(szResultCode, "0000");
    strcpy(szApprovalNo, "1234567890");
	nAmount = 1000;
	strcpy(szOriginalApprovalDate, "20130812112233");
	nOriginalApprovalAmount = 200;
	strcpy(szOriginalApprovalNo, "12345678902");
	strcpy(szSaleCode, "01");
	nResponseFiller = 100;
	strcpy(szIsscompanyCode, "01");
	strcpy(szIsscompanyName, "lotte2");
	strcpy(szCrdAcqCompanyCode, "01");
	strcpy(szCrdAcqCompanyName, "lotte");
	strcpy(szCrdApprovalNo, "12345678901");
	strcpy(szErrorMessage, "SELL CANCEL ERROR MESSAGE");
	nErrorMessageLength = strlen(szErrorMessage);

	nEnco += SetValue(pRsp+nEnco, szResultCode, sizeof(pstRsp->resultCode)); 
	nEnco += SetValue(pRsp+nEnco, "20131013231639000123", sizeof(pstRsp->globalSerialNo)); 
	nEnco += SetValue(pRsp+nEnco, szOriginalApprovalDate, sizeof(pstRsp->originalApprovalDate)); 
	nEnco += SetValueN(pRsp+nEnco, nOriginalApprovalAmount, sizeof(pstRsp->originalApprovalAmount)); 
	nEnco += SetValue(pRsp+nEnco, szOriginalApprovalNo, sizeof(pstRsp->originalApprovalNo)); 
	nEnco += SetValue(pRsp+nEnco, szSaleCode, sizeof(pstRsp->saleCode)); 
	nEnco += SetValue(pRsp+nEnco, szApprovalNo, sizeof(pstRsp->approvalNo)); 
	nEnco += SetValueN(pRsp+nEnco, nAmount, sizeof(pstRsp->amount)); 
	nEnco += SetValueN(pRsp+nEnco, nResponseFiller, sizeof(pstRsp->responseFiller)); 
	nEnco += SetValue(pRsp+nEnco, szIsscompanyCode, sizeof(pstRsp->isscompanyCode)); 
	nEnco += SetValue(pRsp+nEnco, szIsscompanyName, sizeof(pstRsp->isscompanyName)); 
	nEnco += SetValue(pRsp+nEnco, szCrdAcqCompanyCode, sizeof(pstRsp->crdAcqCompanyCode)); 
	nEnco += SetValue(pRsp+nEnco, szCrdAcqCompanyName, sizeof(pstRsp->crdAcqCompanyName)); 
	nEnco += SetValue(pRsp+nEnco, szCrdApprovalNo, sizeof(pstRsp->crdApprovalNo)); 

	nEnco += SetValueN(pRsp+nEnco, nErrorMessageLength, sizeof(pstRsp->errorMessageLength)); 
	nEnco += SetValue(pRsp+nEnco, szErrorMessage, nErrorMessageLength);

	return nEnco;
}


int SimApprovalCancelRsp_setValue(int nThr, char *pRsp, _BGF_MSG *pstBgfReq)
{
	_BGF_MSG	*pstBgfRsp = &DEV_SESS(nThr).stRsp;
	_BGF_APPROVAL_CANCEL_RSP	*pstRsp = &pstBgfRsp->stD.stRsp.stApprovalCancel;

	int			nProductCount, i;
	char		szResultCode[4];
	char		szOriginalApprovalDate[14];
	int			nOriginalApprovalAmount;
	char		szOriginalApprovalNo[20];
	char		szOriginalSaleCode[2];
	int			nAmount;
	char		szApprovalNo[20];
	int			nResponseFiller;
	char		szIsscompanyCode[2];
	char		szIsscompanyName[20];
	int			nErrorMessageLength;
	char		szErrorMessage[128];

	int			nEnco = 0;
	//char		szOut[128];

	memset(pRsp, 0x00, BGF_BODY_SIZE);

	memset(szResultCode, 0x00, sizeof(szResultCode));
	memset(szOriginalApprovalDate, 0x00, sizeof(szOriginalApprovalDate));
	memset(szOriginalApprovalNo, 0x00, sizeof(szOriginalApprovalNo));
	memset(szOriginalSaleCode, 0x00, sizeof(szOriginalSaleCode));
	memset(szApprovalNo, 0x00, sizeof(szApprovalNo));
	memset(szIsscompanyCode, 0x00, sizeof(szIsscompanyCode));
	memset(szIsscompanyName, 0x00, sizeof(szIsscompanyName));
	memset(szErrorMessage, 0x00, sizeof(szErrorMessage));

	/////////////////////////////
	//	BODY
	/////////////////////////////
	//
	
    strcpy(szResultCode, "0000");
	strcpy(szOriginalApprovalDate, "20130812112233");
	nOriginalApprovalAmount = 200;
	strcpy(szOriginalApprovalNo, "12345678902");
	strcpy(szOriginalSaleCode, "01");
	nAmount = 1000;
    strcpy(szApprovalNo, "1234567890");
	nResponseFiller = 100;
	strcpy(szIsscompanyCode, "01");
	strcpy(szIsscompanyName, "lotte2");
	strcpy(szErrorMessage, "APPROVAL CANCEL ERROR MESSAGE");
	nErrorMessageLength = strlen(szErrorMessage);
	
	nEnco += SetValue(pRsp+nEnco, szResultCode, sizeof(pstRsp->resultCode)); 
	nEnco += SetValue(pRsp+nEnco, "20131013231639000123", sizeof(pstRsp->globalSerialNo)); 
	nEnco += SetValue(pRsp+nEnco, szOriginalApprovalDate, sizeof(pstRsp->originalApprovalDate)); 
    nEnco += SetValueN(pRsp+nEnco, nOriginalApprovalAmount, sizeof(pstRsp->originalSettlementAmount)); 
    nEnco += SetValue(pRsp+nEnco, szOriginalApprovalNo, sizeof(pstRsp->originalApprovalNo)); 
    nEnco += SetValue(pRsp+nEnco, szOriginalSaleCode, sizeof(pstRsp->originalSaleCode)); 
    nEnco += SetValueN(pRsp+nEnco, nAmount, sizeof(pstRsp->amount)); 
	nEnco += SetValueN(pRsp+nEnco, 1, sizeof(pstRsp->productCount)); 

	nProductCount = 1;

    Log(LOG_I, "[%4d] productCount(%d)\n", nThr, nProductCount);

	for(i=0; i<nProductCount; i++)
	{
	/* Begin of PLU */
		nEnco += SetValue(pRsp+nEnco, "1000", sizeof(pstRsp->stPlu[i].productId)); 
		nEnco += SetValue(pRsp+nEnco, "1000", sizeof(pstRsp->stPlu[i].productBarcode)); 
		nEnco += SetValue(pRsp+nEnco, "1", sizeof(pstRsp->stPlu[i].productNumber)); 
		nEnco += SetValue(pRsp+nEnco, "10", sizeof(pstRsp->stPlu[i].productProviderCode)); 
		nEnco += SetValue(pRsp+nEnco, "500", sizeof(pstRsp->stPlu[i].productCost)); 
		nEnco += SetValue(pRsp+nEnco, "1000", sizeof(pstRsp->stPlu[i].productCoPrice)); 
		nEnco += SetValue(pRsp+nEnco, "1000", sizeof(pstRsp->stPlu[i].productMaPrice)); 
	/* End of PLU */
	}

	nEnco += SetValue(pRsp+nEnco, "1234567890", sizeof(pstRsp->approvalNo)); 
	nEnco += SetValueN(pRsp+nEnco, 100, sizeof(pstRsp->responseFiller)); 
	nEnco += SetValue(pRsp+nEnco, "01", sizeof(pstRsp->isscompanyCode)); 
	nEnco += SetValue(pRsp+nEnco, "lotte", sizeof(pstRsp->isscompanyName)); 

	nEnco += SetValueN(pRsp+nEnco, nErrorMessageLength, sizeof(pstRsp->errorMessageLength)); 
	nEnco += SetValue(pRsp+nEnco, szErrorMessage, nErrorMessageLength);

	return nEnco;
}

int SimChargeRsp_setValue(int nThr, char *pRsp, _BGF_MSG *pstBgfReq)
{
	_BGF_MSG	*pstBgfRsp = &DEV_SESS(nThr).stRsp;
	_BGF_SELLorCHARGE_RSP	*pstRsp = &pstBgfRsp->stD.stRsp.stSellCharge;

	char		szResultCode[4];
	char		szApprovalNo[20];
	int			nAmount;
	int			nResponseFiller;
	char		szIsscompanyCode[2];
	char		szIsscompanyName[20];
	char		szCrdAcqCompanyCode[2];
	char		szCrdAcqCompanyName[20];
	char		szCrdApprovalNo[2];
	int			nErrorMessageLength;
	char		szErrorMessage[128];

	int			nEnco = 0;

	memset(pRsp, 0x00, BGF_BODY_SIZE);

	memset(szResultCode, 0x00, sizeof(szResultCode));
	memset(szApprovalNo, 0x00, sizeof(szApprovalNo));
	memset(szIsscompanyCode, 0x00, sizeof(szIsscompanyCode));
	memset(szIsscompanyName, 0x00, sizeof(szIsscompanyName));
	memset(szCrdAcqCompanyCode, 0x00, sizeof(szCrdAcqCompanyCode));
	memset(szCrdAcqCompanyName, 0x00, sizeof(szCrdAcqCompanyName));
	memset(szCrdApprovalNo, 0x00, sizeof(szCrdApprovalNo));
	memset(szErrorMessage, 0x00, sizeof(szErrorMessage));

	/////////////////////////////
	//	BODY
	/////////////////////////////
	
    strcpy(szResultCode, "0000");
    strcpy(szApprovalNo, "1234567890");
	nAmount = 1000;
	nResponseFiller = 100;
	strcpy(szIsscompanyCode, "01");
	strcpy(szIsscompanyName, "lotte2");
	strcpy(szCrdAcqCompanyCode, "01");
	strcpy(szCrdAcqCompanyName, "lotte");
	strcpy(szCrdApprovalNo, "12345678");
	strcpy(szErrorMessage, "CHARGE ERROR MESSAGE");
	nErrorMessageLength = strlen(szErrorMessage);
	
	nEnco += SetValue(pRsp+nEnco, szResultCode, sizeof(pstRsp->resultCode));
	nEnco += SetValue(pRsp+nEnco, "20131013231639000123", sizeof(pstRsp->globalSerialNo));
	nEnco += SetValue(pRsp+nEnco, szApprovalNo, sizeof(pstRsp->approvalNo));
	nEnco += SetValueN(pRsp+nEnco, nAmount, sizeof(pstRsp->amount)); 
	nEnco += SetValueN(pRsp+nEnco, nResponseFiller, sizeof(pstRsp->responseFiller)); 
	nEnco += SetValue(pRsp+nEnco, szIsscompanyCode, sizeof(pstRsp->isscompanyCode)); 
	nEnco += SetValue(pRsp+nEnco, szIsscompanyName, sizeof(pstRsp->isscompanyName));
	nEnco += SetValue(pRsp+nEnco, szCrdAcqCompanyCode, sizeof(pstRsp->crdAcqCompanyCode)); 
	nEnco += SetValue(pRsp+nEnco, szCrdAcqCompanyName, sizeof(pstRsp->crdAcqCompanyName)); 
	nEnco += SetValue(pRsp+nEnco, szCrdApprovalNo, sizeof(pstRsp->crdApprovalNo)); 

	nEnco += SetValueN(pRsp+nEnco, nErrorMessageLength, sizeof(pstRsp->errorMessageLength)); 
	nEnco += SetValue(pRsp+nEnco, szErrorMessage, sizeof(pstRsp->errorMessage)); 

	return nEnco;
}

int SimChargeCancelRsp_setValue(int nThr, char *pRsp, _BGF_MSG *pstBgfReq)
{
	_BGF_MSG	*pstBgfRsp = &DEV_SESS(nThr).stRsp;
	_BGF_SELLorCHARGE_CANCEL_RSP	*pstRsp = &pstBgfRsp->stD.stRsp.stSellChargeCancel;

	char		szResultCode[4];
	char		szApprovalNo[20];
	int			nAmount;
	char		szOriginalApprovalDate[14];
	int			nOriginalApprovalAmount;
	char		szOriginalApprovalNo[20];
	char		szSaleCode[2];
	int			nResponseFiller;
	char		szIsscompanyCode[2];
	char		szIsscompanyName[20];
	char		szCrdAcqCompanyCode[2];
	char		szCrdAcqCompanyName[20];
	char		szCrdApprovalNo[8];
	int			nErrorMessageLength;
	char		szErrorMessage[128];
	
	int			nEnco = 0;

	memset(pRsp, 0x00, BGF_BODY_SIZE);

	memset(szResultCode, 0x00, sizeof(szResultCode));
	memset(szApprovalNo, 0x00, sizeof(szApprovalNo));
	memset(szOriginalApprovalDate, 0x00, sizeof(szOriginalApprovalDate));
	memset(szOriginalApprovalNo, 0x00, sizeof(szOriginalApprovalNo));
	memset(szSaleCode, 0x00, sizeof(szSaleCode));
	memset(szIsscompanyCode, 0x00, sizeof(szIsscompanyCode));
	memset(szIsscompanyName, 0x00, sizeof(szIsscompanyName));
	memset(szCrdAcqCompanyCode, 0x00, sizeof(szCrdAcqCompanyCode));
	memset(szCrdAcqCompanyName, 0x00, sizeof(szCrdAcqCompanyName));
	memset(szCrdApprovalNo, 0x00, sizeof(szCrdApprovalNo));
	memset(szErrorMessage, 0x00, sizeof(szErrorMessage));

	/////////////////////////////
	//	BODY
	/////////////////////////////
	
    strcpy(szResultCode, "0000");
    strcpy(szApprovalNo, "1234567890");
	nAmount = 1000;
	strcpy(szOriginalApprovalDate, "20130812112233");
	nOriginalApprovalAmount = 200;
	strcpy(szOriginalApprovalNo, "12345678902");
	strcpy(szSaleCode, "01");
	nResponseFiller = 100;
	strcpy(szIsscompanyCode, "01");
	strcpy(szIsscompanyName, "lotte2");
	strcpy(szCrdAcqCompanyCode, "01");
	strcpy(szCrdAcqCompanyName, "lotte2");
	strcpy(szCrdApprovalNo, "12345678");
	strcpy(szErrorMessage, "CHARGE CANCEL ERROR MESSAGE");
	nErrorMessageLength = strlen(szErrorMessage);
	
	nEnco += SetValue(pRsp+nEnco, szResultCode, sizeof(pstRsp->resultCode)); 
	nEnco += SetValue(pRsp+nEnco, "20131013231639000123", sizeof(pstRsp->globalSerialNo)); 
	nEnco += SetValue(pRsp+nEnco, szOriginalApprovalDate, sizeof(pstRsp->originalApprovalDate)); 
	nEnco += SetValueN(pRsp+nEnco, nOriginalApprovalAmount, sizeof(pstRsp->originalApprovalAmount)); 
	nEnco += SetValue(pRsp+nEnco, szOriginalApprovalNo, sizeof(pstRsp->originalApprovalNo)); 
	nEnco += SetValue(pRsp+nEnco, szSaleCode, sizeof(pstRsp->saleCode)); 
	nEnco += SetValue(pRsp+nEnco, szApprovalNo, sizeof(pstRsp->approvalNo)); 
	nEnco += SetValueN(pRsp+nEnco, nAmount, sizeof(pstRsp->amount)); 
	nEnco += SetValueN(pRsp+nEnco, nResponseFiller, sizeof(pstRsp->responseFiller)); 
	nEnco += SetValue(pRsp+nEnco, szIsscompanyCode, sizeof(pstRsp->isscompanyCode)); 
	nEnco += SetValue(pRsp+nEnco, szIsscompanyName, sizeof(pstRsp->isscompanyName)); 
	nEnco += SetValue(pRsp+nEnco, szCrdAcqCompanyCode, sizeof(pstRsp->crdAcqCompanyCode)); 
	nEnco += SetValue(pRsp+nEnco, szCrdAcqCompanyName, sizeof(pstRsp->crdAcqCompanyName)); 
	nEnco += SetValue(pRsp+nEnco, szCrdApprovalNo, sizeof(pstRsp->crdApprovalNo)); 

	nEnco += SetValueN(pRsp+nEnco, nErrorMessageLength, sizeof(pstRsp->errorMessageLength)); 
	nEnco += SetValue(pRsp+nEnco, szErrorMessage, nErrorMessageLength);

	return nEnco;
}
